#ifndef TCPSERVER_H
#define TCPSERVER_H

#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/epoll.h>
#include <unistd.h>
#include <sys/types.h>
#include <functional>

#include "config.h"
#include "handler.h"
#include "tcpsocket.h"

class EventLoop;
class ThreadPool;

typedef std::function<void(TcpSocket *socket)> NewConnectCallback;

class TcpServer: public Handler
{
public:
    TcpServer(int port, EventLoop *loop, ThreadPool *pool = nullptr);
    ~TcpServer();

    EventLoop *m_evLoop;
    ThreadPool *m_tdPool;

    int listen(void);
    void createNewConnectCallback(NewConnectCallback func);

protected:
    int m_port;
    TCPSocketMap m_socketMap;

private:
    NewConnectCallback m_newConnectFunc;
    void handleAccept();
};

#endif // TCPSERVER_H
